import java.util.Scanner;
/**
 * 登录
 * author:王锦林
 * date:2025-6-13
 */
public class Login {
    public static void main(String[] args) {
        String[] names={"zhangsan","lisi","wangwu"};
        String[] passwords={"333","444","555"};
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名：");
        String inputName=sc.next();
        System.out.println("请输入密码：");
        String inputPassword=sc.next();
        login(names,passwords,inputName,inputPassword);
    }
    public static void login(String[] names,String[] passwords,String name,String password){
        //设置登录条件：用户名和密码不能为空
        if(isName(names,name) && isPassword(passwords,password)){
            System.out.println("登录成功！");
        }
        else{
            System.out.println("用户名或密码错误");
        }
    }
    public static boolean isName(String[] names,String name){
        //如果输入的用户名为空，则返回false
        if(name.isEmpty()){
            return false;
        }
        //根据数组遍历，判断用户名是否在数组中
        for(int i=0;i<names.length;i++){
            if(name.equals(names[i])){
                return true;
            }
        }
        return false;
    }
    public static boolean isPassword(String[] passwords,String password){
        //如果输入的密码为空，则返回false
        if(password.isEmpty()){
            return false;
        }
        //根据数组遍历，判断密码是否在数组中
        for(int i=0;i<passwords.length;i++){
            if(password.equals(passwords[i])){
                return true;
            }
        }
        return false;
    }
}

